package cn.sportvip.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import com.alibaba.fastjson.annotation.JSONField;

@MappedSuperclass
public abstract class TimestampEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Column(name = "modify_time")
	protected Date modifyTime;

	@Column(name = "create_time")
	protected Date createTime;

	@JSONField(serialize = false)
	public Date getModifyTime() {
		return modifyTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	@PrePersist
	public void prePersist() {
		Date now = new Date();
		this.createTime = now;
		this.modifyTime = now;
	}

	@PreUpdate
	public void preUpdate() {
		this.modifyTime = new Date();
	}
}
